package com.dnjn.happiness.cms.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dnjn.happiness.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.tags.Tag;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;

import com.dnjn.happiness.cms.domain.CmsNotice;
import com.dnjn.happiness.cms.service.ICmsNoticeService;
import com.dnjn.happiness.common.core.utils.poi.ExcelUtil;

/**
 * 小程序消息服务Controller
 *
 * @author happiness
 * @date 2023-10-23
 */
@Tag(name = "cms notice 小程序消息服务", description = "小程序消息服务")
@RestController
@RequestMapping("/notice")
public class CmsNoticeController extends BaseController {
    @Autowired
    private ICmsNoticeService cmsNoticeService;

    /**
     * 查询小程序消息服务列表
     */
//    @RequiresPermissions("cms:notice:list")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody CmsNotice cmsNotice, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        Page page = Page.of(current, size);
        Page<CmsNotice> list = cmsNoticeService.page(page, Wrappers.query(cmsNotice));
        return success(list);
    }

    /**
     * 导出小程序消息服务列表
     */
    //@Log(title = "小程序消息服务", businessType = BusinessType.EXPORT)
//    @RequiresPermissions("cms:notice:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsNotice cmsNotice) {
        List<CmsNotice> list = cmsNoticeService.list(Wrappers.query(cmsNotice));
        ExcelUtil<CmsNotice> util = new ExcelUtil<CmsNotice>(CmsNotice.class);
        util.exportExcel(response, list, "小程序消息服务数据");
    }

    /**
     * 获取小程序消息服务详细信息
     */
//    @RequiresPermissions("cms:notice:query")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult get(@PathVariable("noticeId") Long noticeId) {
        return success(cmsNoticeService.getById(noticeId));
    }

    /**
     * 新增小程序消息服务
     */
    //@Log(title = "小程序消息服务", businessType = BusinessType.INSERT)
//    @RequiresPermissions("cms:notice:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CmsNotice cmsNotice) {
        cmsNotice.setCreateBy(SecurityUtils.getUsername());
        return toAjax(cmsNoticeService.save(cmsNotice));
    }

    /**
     * 修改小程序消息服务
     */
    //@Log(title = "小程序消息服务", businessType = BusinessType.UPDATE)
//    @RequiresPermissions("cms:notice:edit")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody CmsNotice cmsNotice) {
        return toAjax(cmsNoticeService.updateById(cmsNotice));
    }

    /**
     * 删除小程序消息服务
     */
    //@Log(title = "小程序消息服务", businessType = BusinessType.DELETE)
//    @RequiresPermissions("cms:notice:remove")
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds) {
        return toAjax(cmsNoticeService.removeBatchByIds(Arrays.asList(noticeIds)));
    }
}
